# -*- encoding: utf-8 -*-

"""
@File:      tc_net_tools_host_func_001.py
@Time:      2024/03/05 14:33:20
@Author:    chenchunhu
@Version:   1.0
@Contact:   wb-cch358909@alibaba-inc.com
@License:   Mulan PSL v2
@Modify:    chenchunhu
"""

from common.basetest import LocalTest

class Test(LocalTest):
    """
    See tc_net_tools_host_func_001.yaml for details

    :avocado: tags=P1,noarch,local,fix
    """
    PARAM_DIC = {"pkg_name": "net-tools"}

    def setUp(self):
        super().setUp(self.PARAM_DIC)

    def test(self):
        code, host_result = self.cmd("host example.com")
        self.assertIn("example.com has address", host_result)
        code, host_result = self.cmd("host 8.8.8.8")
        self.assertIn("dns.google", host_result)
        code, host_result = self.cmd("host example.com 8.8.8.8")
        self.assertIn("example.com has address", host_result)
        code, host_result = self.cmd("host -t MX example.com")
        self.assertIn("example.com mail is handled", host_result)
        code, host_result = self.cmd("host -t NS example.com")
        self.assertIn("example.com name server", host_result)
        code, host_result = self.cmd("host -t SOA example.com")
        self.assertIn("example.com has SOA record", host_result)
        code, host_result = self.cmd("host -t TXT example.com")
        self.assertIn("example.com descriptive text", host_result)
        code, host_result = self.cmd("host -t A example.com")
        self.assertIn("example.com has address", host_result)
        code, host_result = self.cmd("host -t AAAA example.com")
        self.assertIn("example.com has IPv6 address", host_result)
        code, host_result = self.cmd("host -t ANY example.com")
        self.assertIn("example.com host information", host_result)
        code, host_result = self.cmd("host -v example.com")
        self.assertIn('Trying "example.com"', host_result)
        self.cmd("host nonexistentdomain.example > host.log", ignore_status=True)
        code, assertIn=self.cmd("cat host.log", ignore_status=True)
        self.assertIn("not found", assertIn)
        code, host_result = self.cmd("host -t NS @@..", ignore_status=True)
        self.assertIn("not a legal name", host_result)
        code, host_result = self.cmd("host -help", ignore_status=True)
        self.assertIn("Usage:", host_result)

    def tearDown(self):
        super().tearDown(self.PARAM_DIC)
        self.cmd("rm -rf dnsmasq.log")
